package com.power.sifa.approve.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池工具类
 */
public class ThreadPoolUtil {

    public static ThreadPoolExecutor executor;

    static {
        executor = ThreadPoolBuilder
                .ioThreadPoolBuilder()
                .setThreadNamePrefix("shared_threadpool")
                .setMaximumPoolSize(20)
                .builder(10, 20);
    }

    public static ThreadFactory createThreadFactory(String threadNamePrefix, boolean daemon) {
        if (threadNamePrefix != null) {
            return new com.power.sifa.approve.thread.ThreadFactoryImpl(threadNamePrefix, daemon);
        }

        return Executors.defaultThreadFactory();

    }

}
